home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / net / InetSocketAddress.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.5 KB  |  146 lines

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4. import java.io.InvalidObjectException;
  5. import java.io.ObjectInputStream;
  6.  
  7. public class InetSocketAddress extends SocketAddress {
  8.    private String hostname;
  9.    private InetAddress addr;
  10.    private int port;
  11.    private static final long serialVersionUID = 5076001401234631237L;
  12.  
  13.    private InetSocketAddress() {
  14.       this.hostname = null;
  15.       this.addr = null;
  16.    }
  17.  
  18.    public InetSocketAddress(int var1) {
  19.       this(InetAddress.anyLocalAddress(), var1);
  20.    }
  21.  
  22.    public InetSocketAddress(InetAddress var1, int var2) {
  23.       this.hostname = null;
  24.       this.addr = null;
  25.       if (var2 >= 0 && var2 <= 65535) {
  26.          this.port = var2;
  27.          if (var1 == null) {
  28.             this.addr = InetAddress.anyLocalAddress();
  29.          } else {
  30.             this.addr = var1;
  31.          }
  32.  
  33.       } else {
  34.          throw new IllegalArgumentException("port out of range:" + var2);
  35.       }
  36.    }
  37.  
  38.    public InetSocketAddress(String var1, int var2) {
  39.       this.hostname = null;
  40.       this.addr = null;
  41.       if (var2 >= 0 && var2 <= 65535) {
  42.          if (var1 == null) {
  43.             throw new IllegalArgumentException("hostname can't be null");
  44.          } else {
  45.             try {
  46.                this.addr = InetAddress.getByName(var1);
  47.             } catch (UnknownHostException var4) {
  48.                this.hostname = var1;
  49.                this.addr = null;
  50.             }
  51.  
  52.             this.port = var2;
  53.          }
  54.       } else {
  55.          throw new IllegalArgumentException("port out of range:" + var2);
  56.       }
  57.    }
  58.  
  59.    public static InetSocketAddress createUnresolved(String var0, int var1) {
  60.       if (var1 >= 0 && var1 <= 65535) {
  61.          if (var0 == null) {
  62.             throw new IllegalArgumentException("hostname can't be null");
  63.          } else {
  64.             InetSocketAddress var2 = new InetSocketAddress();
  65.             var2.port = var1;
  66.             var2.hostname = var0;
  67.             var2.addr = null;
  68.             return var2;
  69.          }
  70.       } else {
  71.          throw new IllegalArgumentException("port out of range:" + var1);
  72.       }
  73.    }
  74.  
  75.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  76.       var1.defaultReadObject();
  77.       if (this.port >= 0 && this.port <= 65535) {
  78.          if (this.hostname == null && this.addr == null) {
  79.             throw new InvalidObjectException("hostname and addr can't both be null");
  80.          }
  81.       } else {
  82.          throw new InvalidObjectException("port out of range:" + this.port);
  83.       }
  84.    }
  85.  
  86.    public final int getPort() {
  87.       return this.port;
  88.    }
  89.  
  90.    public final InetAddress getAddress() {
  91.       return this.addr;
  92.    }
  93.  
  94.    public final String getHostName() {
  95.       if (this.hostname != null) {
  96.          return this.hostname;
  97.       } else {
  98.          return this.addr != null ? this.addr.getHostName() : null;
  99.       }
  100.    }
  101.  
  102.    final String getHostString() {
  103.       if (this.hostname != null) {
  104.          return this.hostname;
  105.       } else if (this.addr != null) {
  106.          return this.addr.hostName != null ? this.addr.hostName : this.addr.getHostAddress();
  107.       } else {
  108.          return null;
  109.       }
  110.    }
  111.  
  112.    public final boolean isUnresolved() {
  113.       return this.addr == null;
  114.    }
  115.  
  116.    public String toString() {
  117.       return this.isUnresolved() ? this.hostname + ":" + this.port : this.addr.toString() + ":" + this.port;
  118.    }
  119.  
  120.    public final boolean equals(Object var1) {
  121.       if (var1 != null && var1 instanceof InetSocketAddress) {
  122.          InetSocketAddress var2 = (InetSocketAddress)var1;
  123.          boolean var3 = false;
  124.          if (this.addr != null) {
  125.             var3 = this.addr.equals(var2.addr);
  126.          } else if (this.hostname != null) {
  127.             var3 = var2.addr == null && this.hostname.equals(var2.hostname);
  128.          } else {
  129.             var3 = var2.addr == null && var2.hostname == null;
  130.          }
  131.  
  132.          return var3 && this.port == var2.port;
  133.       } else {
  134.          return false;
  135.       }
  136.    }
  137.  
  138.    public final int hashCode() {
  139.       if (this.addr != null) {
  140.          return this.addr.hashCode() + this.port;
  141.       } else {
  142.          return this.hostname != null ? this.hostname.hashCode() + this.port : this.port;
  143.       }
  144.    }
  145. }
  146.